package atguigu.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class VolatileDemo3 implements Callable<Boolean> {

	volatile boolean b = false;

	@Override
	public Boolean call() throws Exception {
		this.setB(true);
		return isB();
	}
	
	public boolean isB() {
		return b;
	}

	public void setB(boolean b) {
		this.b = b;
	}

	public static void main(String[] args) {
		// 资源类
		FutureTask<Boolean> task = new FutureTask<Boolean>(new VolatileDemo3());
		// 开启线程
		new Thread(task,"A").start();
		try {
			Boolean boolean1 = task.get(); // 会产生阻塞作用
			if(boolean1) {
				System.out.println("=================>");
			}else {
				System.out.println("----------------->");
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
